use anyhow::Result;
use std::collections::HashMap;
use serde::{Deserialize, Serialize};

use hyper::{Client, client::HttpConnector};
use jobs::SealWork;
use worker::SealWorkerStats;

pub use sector::{query_sector_status, query_sector_list};

pub mod worker;
pub mod jobs;
pub mod sector;
pub mod pledge;
pub mod types;

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename = "SectorID")]
pub struct SectorId {
    #[serde(rename = "Miner")]
    pub miner: u64,
    #[serde(rename = "Number")]
    pub number: u64,
}

pub async fn query_worker_jobs(client: &Client<HttpConnector>, url: &str, token: &str) -> Result<HashMap<String, Vec<SealWork>>> {
    jobs::query_jobs_from_miner(client, url, token).await
}

pub async fn query_worker_states(client: &Client<HttpConnector>, url: &str, token: &str) -> Result<HashMap<String, SealWorkerStats>> {
    worker::query_worker_from_miner(client, url, token).await
}
